#include "base/eventloop.h"
#include "base/log.h"

#include "base/timeeverymap.h"
namespace net_tools::base
{
  Timeeverymap::Timeeverymap()
      : timeeverymap_(){};
  Timeeverymap::~Timeeverymap(){};
  Timeevery *Timeeverymap::Add_timejob(const std::string job_name, Timeevery *timeevery)
  {
    auto Find = timeeverymap_.find(job_name);
    if (Find == timeeverymap_.end())
    {
      timeeverymap_[job_name] = timeevery;
      return nullptr;
    }
    else
    { //任务重名 删除旧任务
      Timeevery *old = Find->second;
      old->Clean_timeevery();
      Find->second = timeevery;
      return old;
    }
  };
  bool Timeeverymap::Del_timejob(const std::string job_name)
  {
    auto Find = timeeverymap_.find(job_name);
    if (Find == timeeverymap_.end())
    {
      return false;
    }
    else
    {
      Timeevery *del = Find->second;
      timeeverymap_.erase(Find);
      del->Clean_timeevery();
      NT_LOG_INFO << "del timejob" << job_name << NT_LOG_ENDL;
      return true;
    }
  };
  void Timeeverymap::Del_all_timejob()
  {
    for (auto iter : timeeverymap_)
    {
      iter.second->Clean_timeevery();
    }
    timeeverymap_.clear();
  };

} // namespace net_tools::base